home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
626-637
/
disk_629
/
rexxrmf
/
rexxrmf.lzh
/
addressbook.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1991-09-10
|
21KB
|
734 lines
/* Example of simple AddressBook Database */
/* Define the record layout and fields within the record */
/* Note that since none of these variables have been assigned */
/* a value, their value is simply their name strings. */
/* ie. firstname = 'FIRSTNAME' lastname = 'LASTNAME' etc. */
/* the order in which these are specified is the order that */
/* will be used to read/write them in the data file record */
/* This string represents the NAMES of the variables that will */
/* be accessed directly by RexxRMF library */
addrrecord = " firstname lastname street city state zipcode areacode phonenumber dob sendcard"
/* the following are the same as the addrrecord, I use them */
/* when changing or deleting a record. This aint necessary I */
/* just do it this way, you can use the same record layout for */
/* all accesses if you wish. */
addrchange = fnamechg lnamechg streetchg citychg statechg zipchg areachg phonechg dobchg sendchg
addrdelete = fnamedel lnamedel streetdel citydel statedel zipdel areadel phonedel dobdel senddel
/* the data file will be indexed on six fields */
/* index 0 - lastname - */
/* index 1 - state - */
/* index 2 - zipcode - */
/* index 3 - areacode - */
/* index 4 - dob - */
/* index 5 - sendcard - */
/* Define the special variables we want returned */
/* Note you need not specify any special variables be returned, this */
/* is just information for your program */
/* rba - byte location of record within the data file */
/* nodeaddr - this variable will be a hex-string, which will point to */
/* - the treenode in the primary index. */
/* nfields - the number fields in the record or written */
specialrba = " @rba *0nodeaddr %nfields "
/* the following string specifies which variables the record number */
/* will be stored in when the data record is read/written */
/* the variable recnum0 will contain the relative record number for */
/* the key with respect to the primary index. the variable recnum1 */
/* will contain the relative record number for the key with respect to */
/* alternate index 1, etc. */
specialrecn = " =0recnum0 =1recnum1 =2recnum2 =3recnum3 =4recnum4 =5recnum5 "
/* the following string specifies which variables the occurence number */
/* will be stored in when the data record is read/written */
/* the variable occr0 will contain the occurence number for the key in */
/* primary index. the variable occr1 will contain the occurence number */
/* for the key in alternate index 1, etc. */
specialoccr = " #0occr0 #1occr1 #2occr2 #3occr3 #4occr4 #5occr5 "
/* the following string specifies which variables the keys */
/* will be stored in when the data record is read/written */
/* Note the keys are taken from the index NOT the datafile */
/* the variable key0 will contain the key from the primary index */
/* the variable key1 will contain the key from the alternate index 1 */
/* etc. */
specialkey = " &0key0 &1key1 &2key2 &3key3 &4key4 &5key5 "
/* Now create single string with the record layout and special variables */
/* the order in which the strings are concatenated does not matter */
/* But remember variables that are not preceded by a special symbol */
/* will be considered to be the next data field in the record. ie. the */
/* non-special variables are positional */
addrrecord = specialrba specialkey addrrecord specialrecn specialoccr
addrchange = specialrba specialkey addrchange specialrecn specialoccr
addrdelete = specialrba specialkey addrdelete specialrecn specialoccr
x = addlib("RexxRMF.library",0,-30,0) /* make the lib avaiable */
if exists("addrbook") = 0 then
do
x = delete("addrbook")
if exists("addrbook.rmfindex") = 1 then
x = delete("addrbook.rmfindex")
ix = open_rmf("addrbook")
call loaddatafile()
end
else
ix = open_rmf("addrbook")
if ix = '0000 0000'x then /* if NULL did not open */
do
say "Index did not open"
exit
end
do forever
call displaymenu
parse pull msel
msel = upper(msel)
select
when msel = 'Z' then
do
x = read_rmf_record(ix,0,addrrecord,27,'R')
if x = 1 then
call printrecord
x = next_rmf_record(ix,0,addrrecord)
if x = 1 then
call printrecord
x = next_rmf_record(ix,0,addrrecord)
if x = 1 then
call printrecord
x = next_rmf_record(ix,0,addrrecord)
if x = 1 then
call printrecord
x = next_rmf_record(ix,0,addrrecord)
if x = 1 then
call printrecord
end
when msel = 'A' then
do
call addarecord
end
when msel = 'C' then
do
call changearecord
end
when msel = 'K' then
do
call changerecordbykey
end
when msel = 'D' then
do
call deletearecord
end
when msel = 1 then
do
call searchbylastname
end
when msel = 2 then
do
call searchbyzipcode
end
when msel = 3 then
do
call searchbyareacode
end
when msel = 4 then
do
call searchbycardlist
end
when msel = 5 then
do
call searchbyrecordnumber
end
when msel = 6 then
do
call displayarecord
end
when msel = 'I' then
do
call showindexinfo
end
when msel = 'X' then leave
otherwise nop
end
end
x = close_rmf(ix)
say "close returned " x
exit
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
displaymenu:
say " Select Options Menu"
say ""
say " A. Add Record"
say " C. Change Record by Number"
say " K. Change Record by Key"
say " D. Delete Record by Key"
say " I. Index Information (Displays value of all keys)"
say ""
say " 1. Search By LastName"
say " 2. Search By ZipCode"
say " 3. Search By AreaCode"
say " 4. Search By CardList"
say " 5. Search By Record Number"
say " 6. Display All"
say ""
say " X. Exit"
x = writech(stdout," Enter Menu Selection From Above: ")
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
addarecord:
x = writech(stdout," FirstName ? ")
parse pull firstname
x = writech(stdout," LastName ? ")
parse pull lastname
x = writech(stdout," Street ? ")
parse pull street
x = writech(stdout," City ? ")
parse pull city
x = writech(stdout," State ? ")
parse pull state
x = writech(stdout," ZipCode ? ")
parse pull zipcode
x = writech(stdout," areacode ? ")
parse pull areacode
x = writech(stdout," phonenumber ? ")
parse pull phonenumber
x = writech(stdout," Date of Birth ? ")
parse pull dob
x = writech(stdout," Christmas Card ? ")
parse pull sendcard
newkey = upper(lastname) /* gonna use upper case for our keys */
x = write_rmf_record(ix,addrrecord,newkey,1,state,2,zipcode,3,areacode,4,dob,5,sendcard)
/* NOTE the value of 'rba' was set by the write_rmf_record call */
if x = 1 then
say " Record written at location" rba "in file" nfields "fields written"
else
say "Record not written "
return x
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
changearecord:
x = writech(stdout," Record Number ? ")
parse pull updrecnum
/* read the current values in the record, this is VERY important */
/* when doing updating. UPDATE_RMF_RECORD uses the current values */
/* of the ARexx variables in the record layout string */
x = read_rmf_record(ix,0,addrrecord,updrecnum,'R')
if x = 0 then
do
say "Record Not Found"
return 0
end
say ""
say ""
say "Current Record Values"
say ""
call printrecord
say ""
x = writech(stdout," FirstName ? ")
parse pull fnamechg
if fnamechg = "" then
fnamechg = firstname
x = writech(stdout," LastName ? ")
parse pull lnamechg
if lnamechg = "" then
lnamechg = lastname
x = writech(stdout," Street ? ")
parse pull streetchg
if streetchg = "" then
streetchg = street
x = writech(stdout," City ? ")
parse pull citychg
if citychg = "" then
citychg = city
x = writech(stdout," State ? ")
parse pull statechg
if statechg = "" then
statechg = state
x = writech(stdout," ZipCode ? ")
parse pull zipchg
if zipchg = "" then
zipchg = zipcode
x = writech(stdout," areacode ? ")
parse pull areachg
if areachg = "" then
areachg = areacode
x = writech(stdout," phonenumber ? ")
parse pull phonechg
if phonechg = "" then
phonechg = phonenumber
x = writech(stdout," Date of Birth ? ")
parse pull dobchg
if dobchg = "" then
dobchg = dob
x = writech(stdout," Christmas Card ? ")
parse pull sendchg
if sendchg = "" then
sendchg = sendcard
chgkey = upper(lastname)
say " Change to this: "
say " " fnamechg lnamechg
say " " streetchg
say " " citychg statechg zipchg
say " " areachg phonechg
say " " dobchg sendchg
say ""
x = update_rmf_record(ix,addrchange,updrecnum,1,statechg,2,zipchg,3,areachg,4,dobchg,5,sendchg)
if x = 1 then
say " Record Updated "
else
say " Record NOT Updated "
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
changerecordbykey:
x = writech(stdout," Last Name ? ")
parse pull oldkey
oldkey = upper(oldkey)
x = read_rmf_record(ix,0,addrrecord,oldkey,'K')
if x = 0 then
do
say "Record Not Found"
return 0
end
say "Current Record Values "
say ""
call printrecord
say ""
x = writech(stdout," FirstName ? ")
parse pull fnamechg
if fnamechg = "" then
fnamechg = firstname
x = writech(stdout," LastName ? ")
parse pull lnamechg
if lnamechg = "" then
lnamechg = lastname
x = writech(stdout," Street ? ")
parse pull streetchg
if streetchg = "" then
streetchg = street
x = writech(stdout," City ? ")
parse pull citychg
if citychg = "" then
citychg = city
x = writech(stdout," State ? ")
parse pull statechg
if statechg = "" then
statechg = state
x = writech(stdout," ZipCode ? ")
parse pull zipchg
if zipchg = "" then
zipchg = zipcode
x = writech(stdout," areacode ? ")
parse pull areachg
if areachg = "" then
areachg = areacode
x = writech(stdout," phonenumber ? ")
parse pull phonechg
if phonechg = "" then
phonechg = phonenumber
x = writech(stdout," Date of Birth ? ")
parse pull dobchg
if dobchg = "" then
dobchg = dob
x = writech(stdout," Christmas Card ? ")
parse pull sendchg
if sendchg = "" then
sendchg = sendcard
chgkey = upper(lnamechg)
say ""
say " " fnamechg lnamechg
say " " streetchg
say " " citychg statechg zipchg
say " " areachg phonechg
say " " dobchg sendchg
say ""
x = update_rmf_key(ix,addrchange,oldkey,1,chgkey,1,statechg,2,zipchg,3,areachg,4,dobchg,5,sendchg)
if x = 1 then
say " Record Updated "
else
say " Record NOT Updated "
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
deletearecord:
x = writech(stdout,"Last Name ? ")
parse pull key
key = upper(key)
x = delete_rmf_record(ix,0,addrdelete,key,'K',1) /* this always deletes first occurence */
if x = 1 then
do
say ""
say "Record has been deleted "
say " " fnamedel lnamedel "@rba" rba
say " " streetdel
say " " citydel statedel zipdel
say " " areadel phonedel
say " " dobdel senddel
say ""
end
else
say "Record not deleted "
return x
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
displayarecord:
recnum = 1
do forever
x = read_rmf_record(ix,0,addrrecord,recnum,'R')
if x = 0 then leave
call printrecord
recnum = recnum + 1
end
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
searchbystate:
/* index 1 is used for folks in a zip code */
x = writech(stdout," Enter (2 letter abbrv.) State ? ")
parse pull statekey
statekey = upper(statekey)
x = read_rmf_record(ix,1,addrrecord,statekey,'K')
if x = 0 then
do
say " No one in the State of " statekey
return 0
end
do forever
call printrecord
x = next_rmf_record(ix,1,addrrecord)
if x = 0 then leave
end
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
searchbyzipcode:
/* index 2 is used for folks in a zip code */
x = writeln(stdout," partial ZipCode keys will match ")
x = writech(stdout," Enter ZipCode ? ")
parse pull zipkey
zipkey = upper(zipkey)
/* 'partial' keyed read */
x = read_rmf_record(ix,2,addrrecord,zipkey,'P')
if x = 0 then
do
say " Zip Code Not Found"
return 0
end
do forever
call printrecord
x = next_rmf_record(ix,2,addrrecord)
if x = 0 then leave
end
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
searchbyareacode:
/* index 3 is used for folks in an area code */
x = writech(stdout," Enter AreaCode ? ")
parse pull areakey
areakey = upper(areakey)
x = read_rmf_record(ix,3,addrrecord,areakey,'K')
if x = 0 then
do
say ""
say " Area Code NOT FOUND"
say ""
return 0
end
say ""
say " Records with AREACODE " areakey
say ""
do forever
call printrecord
x = next_rmf_record(ix,3,addrrecord)
if x = 0 then leave
end
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
searchbycardlist:
/* index 5 is used for folks on the card list */
x = writeln(stdout," Enter 'Y' to find folks on your Christmas Card List ")
x = writeln(stdout," Enter 'N' to find folks NOT on your Christmas Card List ")
x = writeln(stdout," 'Y' is the default ")
x = writech(stdout," Enter Y/N ? ")
parse pull cardkey
cardkey = upper(cardkey)
x = read_rmf_record(ix,5,addrrecord,cardkey,'K')
if x = 0 then
do
say "No one found "
return 0
end
say ""
if cardkey = 'Y' then
say " Folks on your Chirstmas Card List "
else
say " Folks NOT on your Chirstmas Card List "
say ""
do forever
call printrecord
x = next_rmf_record(ix,5,addrrecord)
if x = 0 then leave
end
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
searchbyrecordnumber:
x = writech(stdout," Enter Record Number ? ")
parse pull recordnum
x = read_rmf_record(ix,0,addrrecord,recordnum,'R')
if x = 0 then
do
say "Record Number" recordnum " NOT FOUND "
return 0
end
/* NOTE 'recnum0' was set by the read_rmf_record call */
/* 'recnum0' is the relative record number for the */
/* record in index0 (the primary index) */
/* 'recnum0' should equal recordnum specified, if */
/* not then their is problem with the RMF lib */
/* the value of 'rba' was also set by the read_rmf */
/* the value of 'occr0' was also set */
say ""
say ""
say " Record" recnum0 "Occurence:" occr0 " at location: " rba
call printrecord
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
searchbylastname:
x = writech(stdout," Last Name? ")
parse pull keyname
keyname = upper(keyname)
x = read_rmf_record(ix,0,addrrecord,keyname,'K')
if x = 0 then
do
say " Record with that NOT FOUND"
return 0
end
do forever /* print first find, then any multiple occurences */
say ""
say ""
say " Record" key0 "Occurence: " occr0 " at location:" rba
call printrecord
x = next_rmf_record(ix,0,addrrecord)
if x = 0 then leave
end
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
showindexinfo:
x = writech(stdout,"Number of records to display ?")
parse pull recnum
say ""
say " LastName State ZipCode AreaCode DOB SendCard "
say " Index0 Index1 Index2 Index3 Index4 Index5 "
say " -------- -------- -------- -------- -------- --------"
say ""
do i = 1 to recnum
x = read_rmf_record(ix,0,addrrecord,i,'R')
if x = 0 then iterate /* leave */
say "RBA:" substr(rba,1,6) substr(key0,1,12) substr(key1,1,9) substr(key2,1,9) substr(key3,1,9) substr(key4,1,9) substr(key5,1,9)
say "RECORD: " substr(recnum0,1,12) substr(recnum1,1,9) substr(recnum2,1,9) substr(recnum3,1,9) substr(recnum4,1,9) substr(recnum5,1,9)
say "OCCURENCE: " substr(occr0,1,12) substr(occr1,1,9) substr(occr2,1,9) substr(occr3,1,9) substr(occr4,1,9) substr(occr5,1,9)
say ""
end
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
loaddatafile: procedure expose ix addrrecord
do forever
x = open(infile,"datafile",'R')
line = readln(infile)
if eof(infile) = 1 then leave
if substr(line,1,1) = '#' then iterate
parse var line firstname ',' lastname ',' street ',' city ',' state ',' zipcode ',' areacode ',' phonenumber ',' dob ',' sendcard
writekey = upper(lastname)
statekey = upper(state)
sendkey = upper(sendcard)
x = write_rmf_record(ix,addrrecord,writekey,1,statekey,2,zipcode,3,areacode,4,dob,5,sendkey)
end
x = close(infile)
return 1
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */
printrecord:
say " Record number:" recnum0 "contains " nfields "fields"
say ""
say " Name :" firstname lastname
say " Street :" street
say " City :" city
say " State :" state
say " Zip :" zipcode
say " Phone :" "(" || areacode || ")" phonenumber
say " DOB :" dob " Christmas Card:" sendcard
say ""
say " *** *** *** "
say ""
return 1